#include "UtilityPCH.h"
#include "UT_CameraProjective.h"
#include "UT_MathHelper.h"

using namespace Utility;

//--------------------------------------------------------------
UT_CameraProjective::UT_CameraProjective(const UT_AnimatedTransform &cam2world, 
	const UT_Transform &proj, const float screenWindow[4], 
	float sopen, float sclose, 
	float lensr, float focald, UT_Film *film)
	: UT_CameraBase(cam2world, sopen, sclose, film)
{
	// Initialize depth of field parameters
	m_fLensRadius = lensr;
	m_fFocalDistance = focald;

	// Compute projective camera transformations
	m_kCameraToScreen = proj;

	// Compute projective camera screen transformations
	m_kScreenToRaster = UT_MathHelper::MakeTransform_Scale(float(film->xResolution),float(film->yResolution), 1.f)
					  * UT_MathHelper::MakeTransform_Scale(1.f / (screenWindow[1] - screenWindow[0]),1.f / (screenWindow[2] - screenWindow[3]), 1.f) 
					  * UT_MathHelper::MakeTransform_Translate(UT_Vec3Float(-screenWindow[0], -screenWindow[3], 0.f));
	
	m_kRasterToScreen = UT_MathHelper::Inverse(m_kScreenToRaster);
	m_kRasterToCamera = UT_MathHelper::Inverse(m_kCameraToScreen) * m_kRasterToScreen;
}
//--------------------------------------------------------------

